package com.ruoyi.qms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.qms.domain.QmsWaste;
import com.ruoyi.qms.service.IQmsWasteService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 废品单Controller
 * 
 * @author ruoyi
 * @date 2022-01-24
 */
@RestController
@RequestMapping("/waste")
public class QmsWasteController extends BaseController
{
    @Autowired
    private IQmsWasteService qmsWasteService;

    /**
     * 查询废品单列表
     */
    @PreAuthorize(hasPermi = "qms:waste:list")
    @GetMapping("/list")
    public TableDataInfo list(QmsWaste qmsWaste)
    {
        startPage();
        List<QmsWaste> list = qmsWasteService.selectQmsWasteList(qmsWaste);
        return getDataTable(list);
    }

    /**
     * 导出废品单列表
     */
    @PreAuthorize(hasPermi = "qms:waste:export")
    @Log(title = "废品单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QmsWaste qmsWaste) throws IOException
    {
        List<QmsWaste> list = qmsWasteService.selectQmsWasteList(qmsWaste);
        ExcelUtil<QmsWaste> util = new ExcelUtil<QmsWaste>(QmsWaste.class);
        util.exportExcel(response, list, "废品单数据");
    }

    /**
     * 获取废品单详细信息
     */
    @PreAuthorize(hasPermi = "qms:waste:query")
    @GetMapping(value = "/{wasteUuid}")
    public AjaxResult getInfo(@PathVariable("wasteUuid") String wasteUuid)
    {
        return AjaxResult.success(qmsWasteService.selectQmsWasteByWasteUuid(wasteUuid));
    }

    /**
     * 新增废品单
     */
    @PreAuthorize(hasPermi = "qms:waste:add")
    @Log(title = "废品单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QmsWaste qmsWaste)
    {
        return toAjax(qmsWasteService.insertQmsWaste(qmsWaste));
    }

    /**
     * 修改废品单
     */
    @PreAuthorize(hasPermi = "qms:waste:edit")
    @Log(title = "废品单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QmsWaste qmsWaste)
    {
        return toAjax(qmsWasteService.updateQmsWaste(qmsWaste));
    }

    /**
     * 删除废品单
     */
    @PreAuthorize(hasPermi = "qms:waste:remove")
    @Log(title = "废品单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wasteUuids}")
    public AjaxResult remove(@PathVariable String[] wasteUuids)
    {
        return toAjax(qmsWasteService.deleteQmsWasteByWasteUuids(wasteUuids));
    }
}
